const { HttpGenerate } = require('../../regist')


class CoinOrderService {


	constructor(allConfig){
		this.allConfig = allConfig;

		const {API_KEY,API_SECRET,API_PASS} = allConfig.account;
		this.http = HttpGenerate(API_KEY,API_SECRET,API_PASS);

	}

	/**
		instId:BTC-USD-SWAP
		获取币种的最新成交价
	*/
	async getTicker(instId){
		const {last} =  await this.http.getTicker(instId);
		return last;
	}

	/**
	 获取可用余额
	*/
	async getUSDTBalance(){
		const {details:[d]} = await this.http.getAccounts("USDT");
		return d.availEq;
	}

	/**
		市价下单
	*/
	async marketOrder(instId,sz){
		return this.http.marketOrder(instId,'cash','buy','market',sz)
	}

}


module.exports = {CoinOrderService}